package pacmanreturns;

import java.net.URL;
import java.awt.*;
import javax.swing.*;

public class GameCanvas extends JPanel {
	private Image buffer;
	private Graphics2D gBuffer;
	private Maze maze;// = new Maze(this);
	private Pacman pacman;

	public GameCanvas() {
			//pacman = new Pacman(this, maze);
			maze.setStart(pacman);
	}

	public void paint(Graphics g) {
		update(g);
	}

	public void update(Graphics g) {
		if (buffer == null) {
			buffer = createImage(Game.WIDTH, Game.HEIGHT);
			gBuffer = (Graphics2D)buffer.getGraphics();
			//gBuffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			//					RenderingHints.VALUE_ANTIALIAS_ON);
		}

		gBuffer.setColor(Color.BLACK);
		gBuffer.fillRect(0, 0, Game.WIDTH, Game.HEIGHT);

		maze.draw();
		pacman.draw();
		g.drawImage(buffer, 0, 0, this);
	}

	public void arc(int x, int y, int width,
					 int height, int startAngle, int arcAngle) {
		gBuffer.fillArc(x, y, width, height, startAngle, arcAngle);
	}

	public void rectangle(int x, int y, int width, int height) {
		gBuffer.fillRect(x, y, width, height);
	}

	public void setColor(Color inColor) {
		gBuffer.setColor(inColor);
	}

	public void move(int inDirection) {
		pacman.setDirection(inDirection);
	}
}